package org.qiuqiu.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Utils {
	//生成MD5的校验码
	public static String md5(String str) {
		 MessageDigest md = null;  
	     try {  
	         md = MessageDigest.getInstance("md5");  
	         md.update(str.getBytes());  
	         byte[] md5Code = md.digest();  
	         StringBuffer strBuf = new StringBuffer();  
	         for (int i = 0; i < md5Code.length; i++)  
	         {  
	             if(md5Code[i] >= 0 && md5Code[i] < 16)  
	             {  
	                 strBuf.append("0");  
	             }  
	             strBuf.append(Integer.toHexString(md5Code[i] & 0xFF));  
	         }  
	         return strBuf.toString();     
	     } catch (NoSuchAlgorithmException e) {  
	         e.printStackTrace();  
	     }  
		return null;
	}
}
